// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
-/* exported NMApplet */
+/* exported Indicator */
const {Atk, Clutter, Gio, GLib, GObject, NM, Polkit, St} = imports.gi;
const Main = imports.ui.main;
-const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const MessageTray = imports.ui.messageTray;
const ModemManager = imports.misc.modemManager;
const Util = imports.misc.util;
+const {QuickMenuToggle, SystemIndicator} = imports.ui.quickSettings;
+
const {loadInterfaceXML} = imports.misc.fileUtils;
const {registerDestroyableType} = imports.misc.signalTracker;
}
});
-const NMSection = GObject.registerClass({
- Properties: {
- 'checked': GObject.ParamSpec.boolean('checked', '', '',
- GObject.ParamFlags.READWRITE,
- false),
- 'icon-name': GObject.ParamSpec.string('icon-name', '', '',
- GObject.ParamFlags.READWRITE,
- ''),
- 'label': GObject.ParamSpec.string('label', '', '',
- GObject.ParamFlags.READWRITE,
- ''),
- },
+const NMToggle = GObject.registerClass({
Signals: {
'activation-failed': {},
},
-}, class NMSection extends GObject.Object {
+}, class NMToggle extends QuickMenuToggle {
constructor() {
super();
- this.menu = new PopupMenu.PopupMenuSection();
-
this._items = new Map();
this._itemSorter = new ItemSorter({trackMru: true});
this, 'label', GObject.BindingFlags.DEFAULT,
(bind, source) => [true, this._transformLabel(source)],
null);
+
+ this.connect('clicked', () => this.activate());
}
setClient(client) {
this._sync();
}
- set visible(visible) {
- this.menu.actor.visible = visible;
- }
-
activate() {
const activeItems = [...this._getActiveItems()];
}
});
-const NMVpnSection = GObject.registerClass(
-class NMVpnSection extends NMSection {
+const NMVpnToggle = GObject.registerClass(
+class NMVpnToggle extends NMToggle {
constructor() {
super();
+ this.menu.setHeader('network-vpn-symbolic', _('VPN'));
this.menu.addSettingsAction(_('VPN Settings'),
'gnome-network-panel.desktop');
}
}
});
-const NMDeviceSection = GObject.registerClass(
-class NMDeviceSection extends NMSection {
+const NMDeviceToggle = GObject.registerClass(
+class NMDeviceToggle extends NMToggle {
constructor(deviceType) {
super();
}
});
-const NMWirelessSection = GObject.registerClass({
- Properties: {
- 'menu-enabled': GObject.ParamSpec.boolean('menu-enabled', '', '',
- GObject.ParamFlags.READWRITE,
- false),
- },
-}, class NMWirelessSection extends NMDeviceSection {
+const NMWirelessToggle = GObject.registerClass(
+class NMWirelessToggle extends NMDeviceToggle {
constructor() {
super(NM.DeviceType.WIFI);
this, 'menu-enabled',
GObject.BindingFlags.INVERT_BOOLEAN);
+ this.menu.setHeader('network-wireless-symbolic', _('Wi–Fi'));
this.menu.addSettingsAction(_('All Networks'),
'gnome-wifi-panel.desktop');
}
}
});
-const NMWiredSection = GObject.registerClass(
-class NMWiredSection extends NMDeviceSection {
+const NMWiredToggle = GObject.registerClass(
+class NMWiredToggle extends NMDeviceToggle {
constructor() {
super(NM.DeviceType.ETHERNET);
+ this.menu.setHeader('network-wired-symbolic', _('Wired Connections'));
this.menu.addSettingsAction(_('Wired Settings'),
'gnome-network-panel.desktop');
}
}
});
-const NMBluetoothSection = GObject.registerClass(
-class NMBluetoothSection extends NMDeviceSection {
+const NMBluetoothToggle = GObject.registerClass(
+class NMBluetoothToggle extends NMDeviceToggle {
constructor() {
super(NM.DeviceType.BT);
+ this.menu.setHeader('network-cellular-symbolic', _('Bluetooth Tethers'));
this.menu.addSettingsAction(_('Bluetooth Settings'),
'gnome-network-panel.desktop');
}
}
});
-const NMModemSection = GObject.registerClass(
-class NMModemSection extends NMDeviceSection {
+const NMModemToggle = GObject.registerClass(
+class NMModemToggle extends NMDeviceToggle {
constructor() {
super(NM.DeviceType.MODEM);
+ this.menu.setHeader('network-cellular-symbolic', _('Mobile Connections'));
+
const settingsLabel = _('Mobile Broadband Settings');
this._wwanSettings = this.menu.addSettingsAction(settingsLabel,
'gnome-wwan-panel.desktop');
}
});
-var NMApplet = GObject.registerClass(
-class Indicator extends PanelMenu.SystemIndicator {
+var Indicator = GObject.registerClass(
+class Indicator extends SystemIndicator {
_init() {
super._init();
this._notification = null;
- this._allSections = [];
-
- this._wiredSection = new NMWiredSection();
- this._wirelessSection = new NMWirelessSection();
- this._modemSection = new NMModemSection();
- this._btSection = new NMBluetoothSection();
- this._vpnSection = new NMVpnSection();
-
- this._deviceSections = new Map([
- [NM.DeviceType.ETHERNET, this._wiredSection],
- [NM.DeviceType.WIFI, this._wirelessSection],
- [NM.DeviceType.MODEM, this._modemSection],
- [NM.DeviceType.BT, this._btSection],
+ this._wiredToggle = new NMWiredToggle();
+ this._wirelessToggle = new NMWirelessToggle();
+ this._modemToggle = new NMModemToggle();
+ this._btToggle = new NMBluetoothToggle();
+ this._vpnToggle = new NMVpnToggle();
+
+ this._deviceToggles = new Map([
+ [NM.DeviceType.ETHERNET, this._wiredToggle],
+ [NM.DeviceType.WIFI, this._wirelessToggle],
+ [NM.DeviceType.MODEM, this._modemToggle],
+ [NM.DeviceType.BT, this._btToggle],
]);
- this._allSections.push(...this._deviceSections.values());
- this._allSections.push(this._vpnSection);
+ this.quickSettingsItems.push(...this._deviceToggles.values());
+ this.quickSettingsItems.push(this._vpnToggle);
- this._allSections.forEach(section => {
- section.connectObject(
+ this.quickSettingsItems.forEach(toggle => {
+ toggle.connectObject(
'activation-failed', () => this._onActivationFailed(),
this);
- this.menu.addMenuItem(section.menu);
});
this._primaryIndicator = this._addIndicator();
this._primaryIndicator, 'icon-name',
GObject.BindingFlags.DEFAULT);
- this._vpnSection.bind_property('checked',
+ this._vpnToggle.bind_property('checked',
this._vpnIndicator, 'visible',
GObject.BindingFlags.SYNC_CREATE);
- this._vpnSection.bind_property('icon-name',
+ this._vpnToggle.bind_property('icon-name',
this._vpnIndicator, 'icon-name',
GObject.BindingFlags.SYNC_CREATE);
async _getClient() {
this._client = await NM.Client.new_async(null);
- this._allSections.forEach(
- section => section.setClient(this._client));
+ this.quickSettingsItems.forEach(
+ toggle => toggle.setClient(this._client));
this._client.bind_property('nm-running',
this, 'visible',
this._configPermission = await Polkit.Permission.new(
'org.freedesktop.NetworkManager.network-control', null, null);
- this._allSections.forEach(section => {
+ this.quickSettingsItems.forEach(toggle => {
this._configPermission.bind_property('allowed',
- section, 'reactive',
+ toggle, 'reactive',
GObject.BindingFlags.SYNC_CREATE);
});
} catch (e) {
_updateIcon() {
const [dev] = this._mainConnection?.get_devices() ?? [];
- const primarySection = this._deviceSections.get(dev?.device_type) ?? null;
- this._primaryIndicatorBinding.source = primarySection;
+ const primaryToggle = this._deviceToggles.get(dev?.device_type) ?? null;
+ this._primaryIndicatorBinding.source = primaryToggle;
- if (!primarySection) {
+ if (!primaryToggle) {
if (this._client.connectivity === NM.ConnectivityState.FULL)
this._primaryIndicator.icon_name = 'network-wired-symbolic';
else
const state = this._client.get_state();
const connected = state === NM.State.CONNECTED_GLOBAL;
- this._primaryIndicator.visible = (primarySection != null) || connected;
+ this._primaryIndicator.visible = (primaryToggle != null) || connected;
}
});